package com.ztn.sdk.iot.api;

import com.fasterxml.jackson.core.type.TypeReference;
import com.ztn.sdk.iot.api.util.HttpTool;
import com.ztn.sdk.iot.api.req.TokenGetReq;
import com.ztn.sdk.iot.api.res.BaseRes;
import com.ztn.sdk.iot.api.res.Token;
import com.ztn.sdk.iot.api.util.JsonTool;

public class IotTokenTool {

    private static final String BASE_PATH = "iot/api/v1/v1/token/";

    public static void refresh(TokenGetReq req) {
        String path = BASE_PATH + "get";
        BaseRes<Token> res = HttpTool.doPost(path, JsonTool.toJson(req), new TypeReference<BaseRes<Token>>() {
        });
        if (null != res && null != res.data && null != res.data.getAccessToken()) {
            String token = res.data.getAccessToken();
            HttpTool.setToken(token);
        }
    }
}
